import 'package:flutter/material.dart';

class AnimTipPage extends StatefulWidget {
  @override
  _AnimTipPageState createState() => _AnimTipPageState();
}

class _AnimTipPageState extends State<AnimTipPage> {
  bool showTipItem = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('点击弹出动画')),
      body: Container(
        child: Column(
          children: <Widget>[
            Container(
              child: AnimatedSwitcher(
                switchInCurve: Cubic(0.4, 0.0, 0.2, 1.0),
                switchOutCurve: Cubic(1.0, 0.1, 1.0, 0.1),
                transitionBuilder: (child, anim) {
                  return SlideTransition(
                    child: child,
                    position: Tween<Offset>(
                      begin: Offset(0.0, -1.0),
                      end: Offset(0.0, 0.0),
                    ).animate(anim),
                  );
                },
                duration: Duration(milliseconds: 300),
                child: showTipItem
                    ? Container(
                        alignment: Alignment.centerLeft,
                        width: MediaQuery.of(context).size.width,
                        height: 70,
                        key: ValueKey('TipItem'),
                        color: Colors.amber,
                        child: Row(
                          children: <Widget>[
                            Icon(Icons.ac_unit, color: Colors.white, size: 13),
                            SizedBox(width: 10),
                            Text(
                              'StickText',
                              style: TextStyle(color: Colors.white),
                            ),
                          ],
                        ),
                      )
                    : Container(key: ValueKey('hideItem')),
              ),
            ),
            Expanded(
              child: Container(
                child: Center(
                  child: FlatButton(
                    onPressed: () {
                      setState(() {
                        showTipItem = true;
                      });
                      Future.delayed(Duration(seconds: 1), () {
                        setState(() {
                          showTipItem = false;
                        });
                      });
                    },
                    child: Text('点击'),
                  ),
                ),
              ),
            )
          ],
        ),
      ),
    );
  }
}
